<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
   <link rel="stylesheet" href="__STATIC__/index/css/quan_common.css">
  <link rel="stylesheet" href="__STATIC__/index/css/single.css">
  <link rel="stylesheet" href="__STATIC__/index/css/common.css">
  <link rel="stylesheet" href="__STATIC__/index/css/main.css">
   <script src="__STATIC__/index/js/jquery-3.2.1.js"></script>
  <title>结算详情</title>
  <style>
    tr{
     height: 40px;
    }
    tr th{
      background: #777;
      color: #fff;
      text-align: center;
      min-width: 100px;
    }
    tr td{
      text-align:center;
      min-width: 100px;
      font-size: 14px;
    }

    .js_zt{
    	width: 100%;
    	padding: 25px 0 25px 50px;
    }
    .js_zt>div{
    	display: inline-block;
    	padding: 5px 10px;
    	margin-right:20px ;
    	font-size: 14px;
    	background: #4c6cc9;
    	border-radius: 5px;
    	color: #fff;
    	cursor: pointer;
    }
    .do_js{
    	float: right;
    }
  </style>
</head>
<body>
	{include file='common/heade'}
		<div class="ext-center">
	     <div class="single_center w_1200">
		       {include file='common/left_tg'}
		       <div class="ext-right">
		       	<div class="e-header-b header-menu-item">
	              <span class="title">结算详情</span>
	          </div>
		        <div class="js_zt">
		        	<div class="havedone" onclick="tiaozhuan(2);">
		        		已结算
		        	</div>
		        	<div class="nodo" onclick="tiaozhuan(0);">
		        		未结算
		        	</div>
		        	<div class="wait" onclick="tiaozhuan(1);">
		        		待审核
		        	</div>
		        	<div class="do_js" onclick="balance();">
		        		结算
		        	</div>
		        </div>
	          <div class="xq_tab">
		       		  <table>
								    <tr>
								    	<th class="all-check">

								    		<label class="check-all ivu-checkbox-wrapper" goods_id="125">
	                          <span class="ivu-checkbox">
	                              <span class="ivu-checkbox-inner"></span>
	                              <input type="checkbox" class="ivu-checkbox-input">
	                          </span>
	                      </label>

								    	</th>
								      <th>ID</th>
								      <th>商品ID</th>
								      <th>订单编号</th>
								      <th>成交金额</th>
								      <th>佣金</th>
								      <th>创建日期</th>
								      <th>商品状态</th>
								      <th>结算状态</th>
								    </tr>
                    {volist name="data.orders" id="vo"}
								     <tr>
								    	<td class="this-check">
								    		<label class="check-style ivu-checkbox-wrapper" status="{$vo.status}" order_id="{$vo.id}" onclick="save_balance_id(this,14)">
                          <span class="ivu-checkbox">
                              <span class="ivu-checkbox-inner"></span>
                              <input type="checkbox" class="ivu-checkbox-input">
                          </span>
                      	</label>
								    	</td>
								      <td>{$vo.id}</td>
								      <td>{$vo.num_iid}</td>
								      <td>{$vo.trade_id}</td>
								      <td>{$vo.alipay_total_price}</td>
								      <td>{$data.goods.money*$data.goods.commision*$vo.item_num/100}</td>
								      <td>{$vo.create_time|date="Y-m-d H:i:s",###}</td>
								      <td>{if condition="($data.goods.status == 2) and ($data.goods.end_time < time())"}推广中{else /}已下架{/if}</td>
								      <td>
                      {switch name="vo.status"}
                          {case value="0"}未结算{/case}
                          {case value="1"}待结算{/case}
                          {default /}已结算
                      {/switch}
                      </td>
								    </tr>
                  {/volist}
								  </table>
                  {$data.page}
								</div>
		       </div>
  	</div>
  </div>
</body>
<script src="__STATIC__/layer/layer.js"></script>
<script>
      var goods_id = {$data.goods.id};

	 		var aLi=document.getElementsByClassName("check-style");
      var lab = document.getElementsByClassName("check-style");

      function ch(){
          var cc = $(".check-all").hasClass("ivu-checkbox-checked"); //false
          var checkLab = [];
          if (cc) {
              for (var i = 0; i < lab.length; i++) {
                  const e = lab[i];
                  checkLab.push(lab[i]);
                  lab[i].classList.add("ivu-checkbox-checked");
                  $(".check-all").addClass("ivu-checkbox-checked")
              }
          }else{
              for (var i = 0; i < lab.length; i++) {
                  const e = lab[i];
                  checkLab.push(lab[i]);
                  lab[i].classList.remove("ivu-checkbox-checked");
                  $(".check-all").removeClass("ivu-checkbox-checked")
              }
          }
      }

      // 全选按钮
      $(".check-all").click(function(){
          if($(".check-all").hasClass("ivu-checkbox-checked")){
              $(".check-all").removeClass("ivu-checkbox-checked")
          }else{
              $(".check-all").addClass("ivu-checkbox-checked")
          }
          ch();
      })

      // 单选
      function save_balance_id(obj,id) {
          $(obj).toggleClass("ivu-checkbox-checked")
          var have_class = $(obj).hasClass('ivu-checkbox-checked');
          if(!have_class){
              // balance_ids.push(id);
              $(".check-all").removeClass('ivu-checkbox-checked')
          }else{
              var onOff=true
              for (var i = 0; i < lab.length; i++) {
                  const e = lab[i];
                  if(lab[i].classList.contains('ivu-checkbox-checked')==false){
                      onOff=false;
                      return;
                  }
              }
              if(onOff){
                  $(".check-all").addClass("ivu-checkbox-checked");
              }
          }
      }

      //结算
      function balance() {
          var h_balance_order=[];
          var n_balance_order = [];
          //balance_order:保存待结算的订单，h_balance_order:保存已结算的订单，n_balance_order:保存未结算的订单
          $(".ivu-checkbox-checked").each(function(index, element) {
              var status = $(this).attr('status');
              var order_id = $(this).attr('order_id');
              if(order_id && order_id != undefined){
                  if(status != 0){
                      h_balance_order.push(order_id);
                  }else{
                      n_balance_order.push(order_id);
                  }
              }
          })
          // console.log(h_balance_order);console.log(n_balance_order);
          if(h_balance_order.length != 0){
              layer.msg('id为'+h_balance_order.join(',')+'的订单不能结算', {icon: 2,time:3000,shade: 0.1});return false;
          }
          $.ajax({
              type:'post',
              url:'{:url("balance_xq")}',
              data:{'ids':n_balance_order.join(','),'goods_id':goods_id},
              beforeSend:function(){
                  layer.msg('请求已提交，请耐心等待后台审核', {icon: 1,time:1500,shade: 0.1});
              },
              success:function(e){
                  // console.log(e);
                  if(e.code == 1){
                      window.location.reload();
                  }else if(e.code == -1){
                      layer.msg(e.result+'不能结算', {icon: 2,time:1500,shade: 0.1});
                  }else{
                      layer.msg(e.msg, {icon: 2,time:1500,shade: 0.1});
                  }
              }
          })
      }

      //订单状态
      function tiaozhuan(status) {
          window.location.href = '/index/Market/balance_xq/goods_id/'+goods_id+'/status/'+status;
      }
</script>
</html>
